package org.hao.samples.dao;

import java.util.List;

import org.hao.samples.model.ExamScore;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@Transactional
public class ExamScoreHibernateDAO extends BaseHibernateDAO<ExamScore> implements IExamScoreDAO {

	@Override
	public List<ExamScore> findExamScoreBystuIdAndsubId(Integer stuId, Integer subId) {
		String hql = "FROM ExamScore as es where es.userId =? and es.subject.sub_id =?";
		Integer params[] = { stuId, subId };
		return this.find(hql, params);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ExamScore> findExamScoreBystuId(Integer stuId) {
		String hql = "FROM ExamScore as es where es.userId =:stuId";
		return this.getSession().createQuery(hql).setInteger("stuId", stuId).list();
	}

	@Override
	public ExamScore findExamScoreById(Integer id) {
		return this.get(id);
	}

	@Override
	public void addExamScore(ExamScore entity) {
		this.save(entity);
	}

	@Override
	public void editExamScore(ExamScore examScore) {
		this.update(examScore);
		;
	}

}
